package team.sun.sss.dao.log;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface LogTalkDao {
    @Select("select log_talk_id,log_stu_date,log_sta_name,log_place,log_content,log_describe,stu_name,stu_college,stu_major,stu_grade,stu_class,log_talk.stu_id" +
            " from log_talk,student where log_talk.stu_id = student.stu_id order by log_stu_date desc")
    List<Map<String,Object>> getLogTalkList();


    @Select("select log_talk_id,log_stu_date,log_sta_name,log_place,log_content,log_describe,stu_name,stu_college,stu_major,stu_grade,stu_class,log_talk.stu_id" +
            " from log_talk,student where log_talk.stu_id = student.stu_id and log_sta_name=#{log_sta} order by log_stu_date desc")
    List<Map<String,Object>> getLogStaTalkList(@Param("log_sta") String log_sta);

    @Insert("insert into log_talk(stu_id,log_stu_date,log_place,log_content,log_describe,log_sta_name) values(#{stu_id},#{log_stu_date},#{log_place},#{log_content},#{log_describe},#{log_sta_name})")
    int addLogTalk(int stu_id, String log_stu_date, String log_place, String log_content, String log_describe, String log_sta_name);

    @Update("update log_talk set stu_id = #{stu_id},log_stu_date = #{log_stu_date},log_place = #{log_place},log_content = #{log_content},log_describe = #{log_describe} where log_talk_id = #{log_talk_id}")
    int updateLogTalk(int log_talk_id, int stu_id, String log_stu_date, String log_place, String log_content, String log_describe);

    @Delete("delete from log_talk where log_talk_id = #{log_talk_id}")
    int deleteLogTalk(@Param("log_talk_id") int id);

    @Select("select log_talk_id,log_stu_date,log_sta_name,log_place,log_content,log_describe,stu_name,stu_college,stu_major,stu_grade,stu_class,log_talk.stu_id" +
            " from log_talk,student where log_talk.stu_id = student.stu_id and log_sta_name=#{sta_name} and (#{stu_name} is null OR stu_name=#{stu_name})  and (#{stu_college} is null OR stu_college=#{stu_college})  and (#{stu_major} is null OR stu_major=#{stu_major})" +
            "order by log_stu_date desc")
    List<Map<String,Object>> getLogStaTalkListSelect(String sta_name, String stu_name,String stu_college,String stu_major);
}
